<template>
  <div class="table-body">
    <el-row :gutter="20">
      <el-col :xs="24" :sm="24" :md="24" :lg="24">
        设备归属：{{deviceLine || '未知'}}
      </el-col>
    </el-row>

    <!--    <el-row :gutter="20">-->
    <!--      <el-col :sm="24" :lg="24">-->
    <!--        <div class="charts-box">-->
    <!--          <div class="charts-box-header">-->
    <!--            Discharge of water-->
    <!--          </div>-->
    <!--          <div class="charts-box-body">-->
    <!--            <div id="chart7" style="width:100%;height: 250px" class="echartMap-line"></div>-->
    <!--          </div>-->
    <!--        </div>-->
    <!--      </el-col>-->
    <!--    </el-row>-->
  </div>
</template>

<script>
import * as echarts from "echarts";
require('echarts/theme/macarons') // echarts theme
const animationDuration = 500
import {deptTreeSelect} from "@/api/system/user";
import {listDept} from "@/api/system/dept";

export default {
  name: "tabDetail",
  props: ['deviceDetail'],
  data() {
    return {
      detailList: [],
      deviceLine: ''
    }
  },
  watch: {
    deviceDetail() {
      console.log('deviceDetail', this.deviceDetail)
      this.getList()
    }
  },
  created() {

  },
  mounted() {
    // deptId
    // let that = this
    // this.$nextTick(function () {
    //   that.initChart()
    // })
  },
  methods: {
    /** 查询部门下拉树结构 */
    // getDeptTree() {
    //   deptTreeSelect().then(response => {
    //     console.log('部门树：', response.data)
    //   });
    // },
    /** 查询部门列表 */
    getList() {
      this.loading = true;
      listDept(this.queryParams).then(response => {
        console.log('部门树：', this.handleTree(response.data, "deptId"))
        let list_ = this.handleTree(response.data, "deptId")
        this.deviceLine = this.findParentsLabel(this.deviceDetail.deptId, list_)
      });
    },
    findParentsLabel(targetName, list, parentNames = '') {
      let that = this
      for (let item of list) {
        if (item.deptId == targetName) {
          return `${parentNames}/${item.deptName}`
        } else if (item.children && Array.isArray(item.children) && item.children.length) {
          let names = that.findParentsLabel(targetName, item.children, `${parentNames}/${item.deptName}`)
          if (names) return names
        }
      }
      return ''
    },
    initChart() {
      this.chart = echarts.init(document.getElementById('chart7'));
      this.chart.setOption({
        tooltip: {
          trigger: 'axis',
          axisPointer: { // 坐标轴指示器，坐标轴触发有效
            type: 'shadow' // 默认为直线，可选为：'line' | 'shadow'
          }
        },
        grid: {
          top: 10,
          left: '2%',
          right: '2%',
          bottom: '3%',
          containLabel: true
        },
        xAxis: [{
          type: 'category',
          data: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12'],
          axisTick: {
            alignWithLabel: true
          }
        }],
        yAxis: [{
          type: 'value',
          axisTick: {
            show: false
          }
        }],
        series: [{
          name: 'pageA',
          type: 'bar',
          stack: 'vistors',
          barWidth: '60%',
          data: [79, 52, 200, 334, 390, 330, 220, 80, 52, 200, 334, 390],
          animationDuration
        }]
      })
    }
  }
}
</script>

<style scoped>
.table-body {
  background: #fff;
  padding: 10px;
  box-shadow: 0 2px 4px 0 rgba(0, 0, 0, .1);
  border: 1px solid #e6ebf5;
  border-radius: 5px;
}

.top-title {
  font-size: 20px;
  color: #333;
  font-weight: 500;
  margin: 0 !important;
}

.top-desc-line {
  display: flex;
  color: #aaa;
}

.charts-box {
  display: flex;
  flex-direction: column;
  padding: 10px;
  background: #fff;
  border-radius: 5px;
  margin-top: 20px;
  box-shadow: 0 2px 4px 0 rgba(0, 0, 0, .1);
}

.charts-box-body {
  width: 100%;
}
</style>
